import Vue from 'vue'
import Router from 'vue-router'
import beforeEach from './beforeEach'
// import afterEach from './afterEach'
Vue.use(Router)

const router = new Router({

  saveScrollPosition:true,
    routes: [
       {
        path: '/auth',
        name: 'auth',
        component: (resolve)=>require(['../pages/auth/index'],resolve),
        meta: {
          title: '身份认证'
        }
      }, {
        path: '/',
        name: 'mainauth',
        component: (resolve)=>require(['../pages/auth/index'],resolve),
        meta: {
          title: '身份认证'
        }
      }, {
        path: '/authPerson',
        name: 'authPerson',
        component: (resolve)=>require(['../pages/authPerson/index'],resolve),
        meta: {
          title: '身份认证'
        }
      },{
        path: '/mlogin',
        name: 'mlogin',
        component: (resolve)=>require(['../pages/mlogin'],resolve),
        meta: {
          title: '登录'
        }
      },{
        path: '/company',
        name: 'company',
        component: (resolve)=>require(['../pages/company'],resolve),
        meta: {
          title: '企业用车'
        }
      },{
        path: '/personCar',
        name: 'personCar',
        component: (resolve)=>require(['../pages/personCar'],resolve),
        meta: {
          title: '个人登录'
        }
      },{
        path: '/center',
        name: 'center',
        component: (resolve)=>require(['../pages/center'],resolve),
        meta: {
          title: '我的'
        }
      }

    ]
})

router.beforeEach(beforeEach);
router.afterEach((to, from)=>{
  var x = to.query.funCode || ''
  console.log(x)

  if(x){
    console.log(window.allRoutes)
    let com = window.getRouter(x)
    console.log(com)
    document.title = com.title;
    console.log(com.title)

  }



});

export default router
